package com.example.demo.gpss;


import api.ConnectRequest;
import api.GpssGrpc;
import api.Session;

/**
 * @author Administrator
 */
public class GPDBSession {
    private GpssGrpc.GpssBlockingStub bStub = null;
    private String gpMasterHost = "172.81.205.216";
    private int gpMasterPort = 5432;
    private String gpUser = "gpadmin";
    private String gpPwd = "gpadmin";
    private String dbName = "gpdb";

    public GPDBSession(GpssGrpc.GpssBlockingStub bStub) {
        this.bStub = bStub;
    }

    /**
     * 建立session连接
     *
     * @return
     */
    public Session getGpssConnection() {
        ConnectRequest connRequest = ConnectRequest.newBuilder()
                .setHost(gpMasterHost)
                .setPort(gpMasterPort)
                .setUsername(gpUser)
                .setPassword(gpPwd)
                .setDB(dbName)
                .setUseSSL(false)
                .build();
        return bStub.connect(connRequest);
    }

    /**
     * 关闭session连接
     *
     * @param session
     */
    public void closeGpssConnection(Session session) {
        bStub.disconnect(session);
    }

}
